package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.RenCaiDao;
import com.bysj.dao.impl.RenCaiDaoImpl;
import com.bysj.entity.RenCai;
import com.bysj.service.RenCaiService;

public class RenCaiServiceImpl implements RenCaiService{
	private RenCaiDao rd=new RenCaiDaoImpl();
	@Override
	public void addRenCai(RenCai rc) {
		String sql="insert into rencai(title,type,time,content) values(?,?,?,?)";
		rd.addRenCai(sql, rc);
	}

	@Override
	public void delRenCai(RenCai rc) {
		String sql="delete from rencai where id= ?";
		rd.delRenCai(sql, rc);
	}

	@Override
	public void updateRenCai(RenCai rc) {

	}

	@Override
	public int CountAllRenCai() {
		String sql="select count(*) from rencai";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public ArrayList<RenCai> FenyeQuery(int page, int rows) {
		String sql="select id,title,type,time,content,docname from rencai limit ?,?";
		return rd.FenyeQuery(sql, page, rows);
	}
	public ArrayList<RenCai> FenyeQueryBytitle(int page, int rows, RenCai rc) {
		String sql="select id,title,type,time,content,docname from rencai where title like '%"+rc.getTitle()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, page, rows);
	}

	@Override
	public ArrayList<RenCai> queryAllRenCai() {
		return null;
	}

	@Override
	public ArrayList<RenCai> queryRenCaiByType(RenCai renCai) {
		String sql="select id,title,type,time,content,docname from rencai where type= ?";
		return rd.queryRCByType(sql,renCai);
	}

	@Override
	public RenCai queryRenCai(RenCai rencai) {
		String sql="select id,title,type,time,content,docname from rencai where id= ?";
		return rd.queryRenCai(sql, rencai);
	}

	@Override
	public void updateRenCaiDocById(RenCai rencai) {
		String sql="update rencai set docname=? where id=?";
		rd.updateRCDocbyId(sql,rencai);
		
	}


	@Override
	public int CountAllRenCaiBytitle(RenCai rc) {
		String sql="select count(*) from rencai where title like '%"+rc.getTitle()+"%' ";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public int CountAllRenCaiBycontent(RenCai rc) {
		String sql="select count(*) from rencai where content like '%"+rc.getContent()+"%' ";
		return rd.CountAllRenCai(sql);
	}
	@Override
	public int CountAllRenCaiBytime(RenCai rc) {
		String sql="select count(*) from rencai where time like '%"+rc.getTime()+"%' ";
		return rd.CountAllRenCai(sql);
	}


	@Override
	public ArrayList<RenCai> FenyeQueryByContent(int nowPage, int pageRowNum,
			RenCai rc) {
		String sql="select id,title,type,time,content,docname from rencai where content like '%"+rc.getContent()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<RenCai> FenyeQueryByTime(int nowPage, int pageRowNum,
			RenCai rc) {
		String sql="select id,title,type,time,content,docname from rencai where time like '%"+rc.getTime()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public int CountRenCaiByContent(RenCai rencai) {
		String sql="select count(*) from rencai where content like '%"+rencai.getContent()+"%' ";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public int CountRenCaiByTime(RenCai rencai) {
		String sql="select count(*) from rencai where time like '%"+rencai.getTime()+"%' ";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public int CountUserByTitle(RenCai rencai) {
		String sql="select count(*) from rencai where title like '%"+rencai.getTitle()+"%' ";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public int CountRenCaiById(RenCai rencai) {
		String sql="select count(*) from rencai where id like '%"+rencai.getId()+"%' ";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public int CountUserByType(RenCai rencai) {
		String sql="select count(*) from rencai where type like '%"+rencai.getType()+"%' ";
		return rd.CountAllRenCai(sql);
	}

	@Override
	public ArrayList<RenCai> FenyeQueryById(int nowPage, int pageRowNum,
			RenCai rencai) {
		String sql="select id,title,type,time,content,docname"
				+ " from rencai where id like '%"+rencai.getId()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<RenCai> FenyeQueryrcByContent(int nowPage, int pageRowNum,
			RenCai rencai) {
		String sql="select id,title,type,time,content,docname"
				+ " from rencai where content like '%"+rencai.getContent()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<RenCai> FenyeQueryByTitle(int nowPage, int pageRowNum,
			RenCai rencai) {
		String sql="select id,title,type,time,content,docname"
				+ " from rencai where title like '%"+rencai.getTitle()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<RenCai> FenyeQueryByType(int nowPage, int pageRowNum,
			RenCai rencai) {
		String sql="select id,title,type,time,content,docname"
				+ " from rencai where type like '%"+rencai.getType()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<RenCai> FenyeQueryrcByTime(int nowPage, int pageRowNum,
			RenCai rencai) {
		String sql="select id,title,type,time,content,docname"
				+ " from rencai where time like '%"+rencai.getTime()+"%' limit ?,? ";
		return rd.FenyeQuery(sql, nowPage, pageRowNum);
	}
}
